#include <array>
#include <fstream>
#include <vector>
using namespace std;

long long dfs(const vector<int>& arr, int i, vector<bool>& color)
{
    if (i == arr.size()) {
        long long result = 0;
        array<int, 2> prev_color{-1, -1};
        for (int j = 0; j < arr.size(); ++j) {
            if (prev_color[color[j]] != -1 &&
                arr[prev_color[color[j]]] == arr[j]) {
                result += arr[prev_color[color[j]]];
            }

            prev_color[color[j]] = j;
        }

        return result;
    } else {
        long long res1 = dfs(arr, i + 1, color);
        color[i] = true;
        long long res2 = dfs(arr, i + 1, color);
        color[i] = false;
        return max(res1, res2);
    }
}

int main()
{
    ifstream input("color.in");
    ofstream output("color.out");
    int t;
    input >> t;
    while (t--) {
        int n;
        input >> n;
        vector<int> arr(n);
        for (auto& e : arr) {
            input >> e;
        }

        vector<bool> color(n);
        output << dfs(arr, 0, color) << '\n';
    }

    return 0;
}